<?php
			ob_start();			
?>
<?php
		
		if (isset($_COOKIE["user"])) {
			// if cookie <> ""
		  }
		  else
		  {
			   header("location:login.php");
			  
		  }
?>
<!-- begin ckeidtor -->
<script type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({			 
	theme : "advanced",
	mode : "textareas",
    plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
	// Theme options
	theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect",
	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,forecolor,backcolor",
	theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,fullscreen,insertfile,insertimage",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : true,
	theme_advanced_font_sizes : "10px,12px,14px,16px,24px",
});
</script>
<!-- end cheditor-->

<?php
	$act_id = $_REQUEST["act_id"];	
	if(isset($_REQUEST["act_id"]))
	{
		
		
		$sql = "SELECT * FROM tbl_activity WHERE act_id={$act_id} LIMIT 1";
		$result = query($sql);
		$row = fetch_assoc($result);
					
		$message=stripcslashes($row["message"]);
		$title=$row["act_title"];
		$published=$row["published"];
		$uploadfile = $row["photo"];

	}
?>
<?php
                    if(isset($_POST["btnsubmit"]))
                    {
						$fieldimage = "";
						$oldfilename = $_POST["txtoldimage"];
						$newfilename = escapeValue($_FILES["uploadfile"]["name"]);

						$act_id = $_POST["txtact_id"];
						$title=escapeValue($_POST["txttitle"]);
						$message=escapeValue($_POST["txtmessage"]);
						$published=escapeValue($_POST["cbopublished"]);
						
						
							if(@$errors == "")
							{
								//upload new photo
								if($newfilename != "")
								{
									// Block rezier image
											$photo = validImage("uploadfile",5000, 5000);		
												//validImage($file,$imgX, $imgY);
												if ($photo === true){
																		
												//Upload Image
												$image_name = $_FILES["uploadfile"]["name"];
												$image_tmp_name = $_FILES["uploadfile"]["tmp_name"];
												$ext = "jpg";	
												$tag = "";
												$path = "actuality/";
												//$filename = "$photoid.$ext";
												$filename=$image_name;		
												$width = 220;
												$height = 160;
												
												createImageAndThumb($image_tmp_name,$filename,
																	$width,
																	$height,
																	$tag,
																	$path,
																	$image_name);
										//end upload image					
												
												}
										//end block rezier image
									
										//concetenate field name
										$fieldimage = ", photo='$newfilename'";
										
										$sql = "UPDATE tbl_activity SET message='$message',  
													act_title='$title' ,published='$published'
												    ,date_post=now() {$fieldimage} WHERE act_id={$act_id}" ;													
											if(query($sql))
											{
												//if update successful delete old photo
												if($fieldimage != "")
												{
													deleteFile("actuality/{$oldfilename}");
													$oldfilename = $newfilename;
													//direct to itself and get sli_id=ocure sli_id
													//pageRedirect("newsEdit.php?act_id=$act_id","");
												}	
												errorMessage("Mise à jour réussie ...!");
											}
												
								}
								else // else newfile photo =""
								{
											$sql = "UPDATE tbl_activity SET message='$message',  
													act_title='$title' ,published='$published'
												    ,date_post=now() WHERE act_id={$act_id}" ;													
											if(query($sql))
											{
												//direct to itself and get sli_id=ocure sli_id
												//pageRedirect("newsEdit.php?act_id=$act_id","");
													
												errorMessage("Mise à jour réussie ...!");
											}
											
								}								
							}// end error=""
							
                    } //end isset btnsubmit
                ?>

                	<div id="border_cont_title">
                        	<div id='content_title_left'>modifier Actualite</div>
                            <div id='content_title_right'></div>
					</div> <!--end border_cont_title-->
                    <?php echo @$errors;?>
                    	 <!--start table -->
                    <form action="index.php?page=actualityEdit&act_id=<?php echo $act_id;?>" method="post" enctype="multipart/form-data">
                    	<table width="765px" align="left">
                        	<tr>
                            	<input type="hidden" value="<?php echo $act_id; ?>" name="txtact_id" />
                                
                                <input type="hidden" value="<?php echo @$uploadfile; ?>" name="txtoldimage" />
                            	<td align="left" height="30" bgcolor="#FFEAD7">Envoyer la photo*</td>
                                <td>
                                	<input class="submit" type="file" name="uploadfile" /><img src="actuality/<?php echo @$uploadfile ;?>" width="80px" height="70px" />
                                </td>
                                
                            </tr>
                            <tr>
                            	<td align="left" height="30" bgcolor="#FFEAD7">Titre</td>
                                <td>
                                <input type="text" name="txttitle" value="<?php echo @$title; ?>"  />
                                </td>
                            </tr>
                            <tr>
                            	
                                <td colspan="2">
                                <textarea name="txtmessage" class="ckeditor" cols="40" rows="10" id="txtmessage" wrap="virtual"><?php echo stripcslashes(@$message); ?></textarea>
                                </td>
                            </tr>
                            <tr>
                            	<td align="left" height="30" bgcolor="#FFEAD7">Publier</td>
                                <td align="left" height="30">
                                	<select name="cbopublished" >
                                       <option value=""> -- Sélectionnez Publier -- </option>
									<?php
										$sql = "SELECT * FROM tbl_zeroone";
                                    $result = query($sql);
                                    while($row = fetch_assoc($result))
                                    {
                                        
                                        if(@$published == $row['zeroone_value'])
                                            $selected = " selected='selected'";
											
                                        else	
                                            $selected = "";
                                	?>
                                        <option value="<?php echo $row['zeroone_value'];?>"<?php echo $selected;?>>
                                        <?php echo $row['zeroone_name'];?></option>
                                        
                                	<?php
										
                                    }
                                   
                                  	?>
                                        
                                    </select>
                                </td>
                            </tr>
                            <tr>
                            	<td align="left" height="30" bgcolor="#FFEAD7">Action</td>
                                <td align="left" height="30">
                                <input class="submit" type="submit" name="btnsubmit" value="Soumettre"  />
                                <input class="submit" type="button" name="btncancel" value="Annuler" onclick="redirect('index.php?page=actuality')" />
                                </td>
                            </tr>
                            
                        </table>
                        </form>
                    <!--end table -->
                   